package com.example.littlepainter.db

import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase
import androidx.room.TypeConverters
import com.example.littlepainter.utils.Helper

@Database(
    entities = [Picture::class],
    version = 1,
    exportSchema = false
)
@TypeConverters(BitmapConverter::class)
abstract class PictureDatabase : RoomDatabase() {
    abstract fun pictureDao(): PictureDao

    companion object {
        private var database: PictureDatabase? = null
        fun db(): PictureDatabase {
            if (database != null) return database!!
            synchronized(this) {
                if (database == null) {
                    database = Room.databaseBuilder(
                        Helper.mContext.get()!!,
                        PictureDatabase::class.java,
                        "picture.db"
                    ).build()
                }
            }
            return database!!
        }
    }
}